package org.wzl.personalwebsite.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.wzl.personalwebsite.enumerate.RespCode;

/**
 * @author 卫志龙
 * @version 1.0
 * @date 2024/9/21 17:56
 */
@Data
@AllArgsConstructor
public class Resp<T> {

    private T data;
    private String msg;
    private Integer code;

    public Resp(T data, RespCode respCode) {
        this.data = data;
        this.msg = respCode.getMsg();
        this.code = respCode.getCode();
    }

    public static <T> Resp<T> ok() {
        return new Resp<>(null, RespCode.SUCCESS);
    }

    public static <T> Resp<T> ok(T data) {
        return new Resp<>(data, RespCode.SUCCESS);
    }

    public static <T> Resp<T> fail(RespCode respCode) {
        return new Resp<>(null, respCode);
    }

    public static <T> Resp<T> fail(T data, RespCode respCode) {
        return new Resp<>(data, respCode);
    }

}
